/*
 * topological-hex, a program to compute combinatorial hexahedral meshes.
 *
 * Copyright (C) <2018> <Université catholique de Louvain (UCL), Belgique>
 *
 * List of the contributors to the development, description and complete
 * License: see LICENSE file.
 *
 * This program (topological-hex) is free software:
 * you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (see COPYING file).  If not,
 * see <http://www.gnu.org/licenses/>.
 */

#include <check.h>

#include "dual.h"
#include "input.h"

static
bool check_intersection(const char *path) {
  mesh mesh;
  ck_assert(mesh_load(&mesh, path) == SUCCESS);
  ck_assert(mesh_reserve(&mesh, 20) == SUCCESS);

  solver solver;
  ck_assert(solver_init(&solver, &mesh, mesh.num_vertices,
                        SOLVER_SHELLABLE_ONLY) == SUCCESS);

  bool result = dual_contains_self_intersection(&solver);

  solver_release(&solver);
  mesh_release(&mesh);

  return result;
}

START_TEST(test_dual) {
  ck_assert(check_intersection(INPUT_DIR "/spindle.mesh"));
  ck_assert(!check_intersection(INPUT_DIR "/single-hex.mesh"));
  ck_assert(!check_intersection(INPUT_DIR "/two-hex.mesh"));
  ck_assert(!check_intersection(INPUT_DIR "/rhombic-dodecahedron.mesh"));
  ck_assert(!check_intersection(INPUT_DIR "/tetrahedron.mesh"));
  ck_assert(!check_intersection(INPUT_DIR "/prism.mesh"));
  ck_assert(check_intersection(INPUT_DIR "/erickson-buffer-a.mesh"));
  ck_assert(check_intersection(INPUT_DIR "/erickson-buffer-b.mesh"));
} END_TEST

Suite *dual_suite(void) {
  Suite *s = suite_create("Dual");

  TCase *tcase = tcase_create("dual");
  tcase_add_test(tcase, test_dual);
  suite_add_tcase(s, tcase);

  return s;
}
